//
//  CRPhotosView.m
//  CRChatRoom
//
//  Created by lanou3g on 15/11/24.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRPhotosView.h"

@interface CRPhotosView ()



@end

@implementation CRPhotosView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
    }
    return self;
}


- (void)addImage:(UIImage *)image
{
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = image;
    [self addSubview:imageView];
    
}

// 计算图片的frame
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    int maxCoumns = 5;  // 每行最多显示4张
    CGFloat margin = 5; // 间距
    CGFloat imageW = 60;  // 每张图片的宽度
    for (int i = 0; i < self.subviews.count; i++) {
        UIImageView *View = self.subviews[i];
        CGFloat X = margin + (i % maxCoumns) * (margin + imageW);
        CGFloat Y = (i / maxCoumns) * (margin + imageW);
        View.frame = CGRectMake(X, Y, imageW, imageW);

    }



    
}

@end













